package com.sky.service.Setmeal;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.setmeal.SetMealDTO;
import com.sky.entity.SetMeal;
import com.sky.mapper.SetMealMapper;
import com.sky.mapper.SetmealDishMapper;
import com.sky.result.PageResult;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 褚金龙
 * @Date 2024/9/22 22:30
 */

@Service
public class SetmealServiceImpl implements SetmealService{
    @Autowired
    private SetMealMapper setMealMapper;
    @Autowired
    private SetmealDishMapper setmealDishMapper;

    /**
     * 添加套餐
     * @param setMeal
     */

    @Override
    public void addSetMeal(SetMeal setMeal) {
        SetMeal s=new SetMeal();
        BeanUtils.copyProperties(setMeal,s);
       setMealMapper.addSetMeal(s);
        Long id = s.getId();
        //向套餐和菜品表添加id
       // setmealDishMapper.setMealInsert(id);
    }

    /**
     * 查询套餐
     * @return
     */

    @Override
    public PageResult query(SetMealDTO setMealDTO) {
        PageHelper.startPage(setMealDTO.getPage(),setMealDTO.getPageSize());
        Page<SetMeal> pageResults =setMealMapper.select(setMealDTO);
        return new PageResult(pageResults.getTotal(),pageResults);
    }

    /**
     * 回显套餐
     * @param id
     * @return
     */

    @Override
    public SetMeal getByIdSetMeal(Long id) {
        SetMeal setMeal=   setMealMapper.getByIdSetMeal(id);
        return setMeal;
    }

    /**
     * 修改套餐
     * @param setMeal
     */
    @Override
    public void updateSetMeal(SetMeal setMeal) {
        setMealMapper.updateSetMeal(setMeal);
    }


    /**
     *  删除套餐
     * @param ids
     */
    @Override
    public void deleteSetMeal(List<Long> ids) {
        setMealMapper.deleteSetMeal(ids);
    }

    /**
     * 根据id修改状态
     * @param status
     * @param id
     */
    @Override
    public void updateStatus(Integer status, Long id) {
        setMealMapper.updateStatus(status,id);
    }


}
